package com.zhanyd.app.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.zhanyd.app.common.ApiResult;
import com.zhanyd.app.common.util.HttpService;
import com.zhanyd.app.common.util.MD5Generate;

@RestController
@EnableAutoConfiguration
@RequestMapping("/remote")
public class RemoteComtroller {

	 private Logger logger = LoggerFactory.getLogger(this.getClass());
	 
	 /**
     * 获取加水量信息
     * @return
     */
    @RequestMapping("/getWaterByPailNo")
    public ApiResult<String> getWaterByPailNo(){
    	logger.info("getWaterByPailNo");
    	ApiResult<String> apiResult = new ApiResult<String>();

    	JSONObject param = new JSONObject();
    	JSONObject head = new JSONObject();
    	JSONObject data = new JSONObject();
    	
    	long currentTime = System.currentTimeMillis();
    	String psw = MD5Generate.getMD5("FBL7Zc3l".getBytes());
    	System.out.println("psw = " + psw);
    	String beforeSign = "getWaterByPailNo" + currentTime + psw.toLowerCase();
    	String sign = MD5Generate.getMD5(beforeSign.getBytes());
    	
    	head.put("company_num", "10581");
    	head.put("key", currentTime);
    	head.put("sign", sign.toUpperCase());
    	
    	data.put("pail_no", "1100001");
    	
    	String url = "http://www.kmzhyf.cn:8192/zyf/service/waterService/getWaterByPailNo";
    	param.put("head",head);
    	param.put("data",data);
    	String result = HttpService.post(url, param.toJSONString());
    	logger.info(result);
    	System.out.println(result);
    	return apiResult.success(result);
    }
}
